package com.wg.service.serviceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wg.dao.UserDao;
import com.wg.entity.User;
import com.wg.mapper.UserMapper;
import com.wg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired(required = false)
    private UserDao userDao;
    @Override
    public IPage<User> findListByPage(Integer page, Integer pageCount){
        IPage<User> wherePage = new Page<>(page, pageCount);
        User where = new User();

        return   baseMapper.selectPage(wherePage, Wrappers.query(where));
    }

    @Override
    public boolean add(User user) {
        return userDao.addUser(user);
    }

    @Override
    public boolean delete(Integer id) {
        return userDao.deleteById(id);
    }

    @Override
    public boolean updateData(User user) {
        return userDao.updateById(user);
    }

    @Override
    public User findById(Integer id) {
        return userDao.findById(id);
    }


    @Override
    public PageInfo<User> findUserAll(int page, int pageSize, User user) {
        PageHelper.startPage(page,pageSize);
        //查询的结果集
        List<User> list=userDao.findAll();
        PageInfo<User> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public User queryUserByNameAndPwd(User user) {
        return userDao.queryUserByNameAndPwd(user);
    }


}
